<?php namespace Common\Model;
use Hdphp\Model\Model;
class Cate extends Model{
	protected $table="class";
//	
	protected $validate=array(
		array('cname','required','分类名称不能为空',3,3),
		array('cname','maxlen:20','分类名称不能超过二十个字',3,3),
	);
	
	public function store(){
		if($this->create()){
			return $this->add();
		}else{
			return false;
		}
	}

	
	public function edit(){
		if($this->create()){
			
			$this->save();
		
			return true;
		}else{
			return false;
		}
	}
	
	
	public function getNoMy($cid){
		//获得当前分类的子集的cid
		$cids = $this->getMyson($this->get(), $cid);
		//把自己的cid压入
		$cids[] = $cid;
		

		//把cid集合分成字符串
		$cids=implode(',', $cids);
		
		//获得除了自己和自己的子集的数据
		$data=$this->where("cid not in($cids)")->get();

//		//查看运行的sql,调试的时候使用
//		$log = $this->getQueryLog();
//		p($log);
		$data = Data::tree($data,'cname');
		return $data;
		
	}
	
	public function getMyson($data,$cid){
	    //查找pid等于$cid的数据的cid
	    $arr=array();
		
		foreach ($data as $v) {
			if($v['pid']==$cid){
				$arr[]=$v['cid'];
				$arr=array_merge($arr,$this->getMyson($data,$v['cid']));
			}
		}
		return $arr;
	}
	
	
	
	
}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
?>